#include "iservice_module_info_impl.h"
#include "../../include/ivariant_impl.h"
#include "../../include/ivariant_helper.h"

#include <list>

namespace Boss
{

  TResult BOSS_CALL_TYPE IServiceModuleInfoImpl::GetModuleId(IVariant **moduleId) const
  {
    if (!moduleId || *moduleId)
      return rcBadParam;
    ISyncObject Lock(GetSynObj());
    return ModuleId.Get() ? ModuleId.QueryInterface(moduleId) : rcFail;
  }

  TResult BOSS_CALL_TYPE IServiceModuleInfoImpl::GetModuleCoClasses(IEnum **coClassIds) const
  {
    if (!coClassIds || *coClassIds)
      return rcBadParam;
    ISyncObject Lock(GetSynObj());
    return CoClassIds.Get() ? CoClassIds.QueryInterface(coClassIds) : rcFail;
  }

  TResult BOSS_CALL_TYPE IServiceModuleInfoImpl::GetModulePath(IVariant **path) const
  {
    if (!path || *path)
      return rcBadParam;
    ISyncObject Lock(GetSynObj());
    return ModulePath.Get() ? ModulePath.QueryInterface(path) : rcFail;
  }

  TResult BOSS_CALL_TYPE IServiceModuleInfoImpl::GetModuleName(IVariant **path) const
  {
    if (!path || *path)
      return rcBadParam;
    ISyncObject Lock(GetSynObj());
    return ModulePath.Get() ? ModulePath.QueryInterface(path) : rcFail;
  }

  void IServiceModuleInfoImpl::SetModuleId(const std::string &moduleId)
  {
    IVariantHelper Helper(ModuleId = IBaseImpl<IVariantImpl>::Create(GetSynObj()));
    Helper = moduleId.c_str();
  }

  void IServiceModuleInfoImpl::AddModuleCoClassesId(const std::string &coClassId)
  {
    if (!CoClassIds.Get())
      CoClassIds = IBaseImpl<IEnumImpl>::Create(GetSynObj());
    RefObjPtr<IVariant> Item = IBaseImpl<IVariantImpl>::Create(GetSynObj());
    IVariantHelper Helper(Item);
    Helper = coClassId.c_str();
    CoClassIds->AddItem(Item);
  }

  void IServiceModuleInfoImpl::SetModulePath(const std::string &path)
  {
    IVariantHelper Helper(ModulePath = IBaseImpl<IVariantImpl>::Create(GetSynObj()));
    Helper = path.c_str();
  }

  void IServiceModuleInfoImpl::SetModuleName(const std::string &name)
  {
    IVariantHelper Helper(ModuleName = IBaseImpl<IVariantImpl>::Create(GetSynObj()));
    Helper = name.c_str();
  }

}
